#!/bin/bash
#序列号
Serial_Number=$(dmidecode -t 1|grep "Serial Number"|awk -F':' '{print $2}')
# 超线程
ThreadsNum=$(lscpu |grep 'Thread(s) per core'|awk '{print $4}')
#服务器型号
Product_Name=$(dmidecode -t 1|grep "Product Name"|awk -F':' '{print $2}')
# 核心
#Core_Num=$(lscpu | grep 'CPU(s):' | head -1 | awk '{print $2}')

CPU_Nums=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c|sed 's/^[ ]*//g')
CPU_Physical=$(cat /proc/cpuinfo| grep "physical id"|sort -n|uniq|wc -l)
CPU_Cores=$(cat /proc/cpuinfo| grep "cpu cores"| uniq|awk '{print $NF}')
CPU_INFO="总核心:$CPU_Nums [${CPU_Physical}*${CPU_Cores}]"

Total_Mem=0
Total_cards=$(dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range|wc -l)
Used_cards=$(dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range|grep -v "No Module"|wc -l)
Mem_List=()
OLD_IFS=$IFS
IFS=$'\n' #换行符作为分隔符
if [[ $ThreadsNum -ne 1 ]] ;then
	Flag="已开超线程CPU[$ThreadsNum]"
fi
for i in $(dmidecode|grep -P -A5 "Memory\s+Device"|grep Size|grep -v Range|grep -v "No Module"|awk '{print $2,$3}') ;do
    value=$(echo $i|awk '{print $1}')
    flag=$(echo $i|awk '{print $2}')
    if [[ "$flag" == "MB" ]] ;then
        value=$((${value}/1024))
	fi
    Total_Mem=$(($Total_Mem+$value))
    Mem_List+=($value)
done
IFS=$OLD_IFS # 恢复默认值
 
Mem_INFO="${Total_Mem}GB[卡槽 ${Used_cards}/${Total_cards}]"

Root_Size=$(df -h /|tail -1|awk '{print $2}')
Home_Size=$(df -h /home|tail -1|awk '{print $2}')
Disk_INFO="[/目录]: ${Root_Size} [home目录]: ${Home_Size}"
    
echo "${Flag} ${Serial_Number},${Product_Name},${CPU_INFO},${Mem_INFO},${Disk_INFO}"
#echo '[总核心] = 物理CPU数量 * 单个核心数量 * 线程数量 (如果有2个物理CPU, 单个CPU是32核,总共是128核心,那说明2个物理CPU有线程技术)'


